/*	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------*/
/*!	@file	<xeres.h>
///	@path	~/src/
///	@date	2007/06/12
///	@desc	global declarations.
*/

/* ANSI C compatible. */

#pragma once

/* Introduce frequently used CRT header. */
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <limits.h>
#include <float.h>
#include <new.h>
#include <memory.h>
#include <malloc.h>

/* Workaround for WINSDK 6.x error. */
#define _interlockedbittestandset fk_ms_set
#define _interlockedbittestandreset fk_ms_reset
#define _interlockedbittestandset64 fk_ms_set64
#define _interlockedbittestandreset64 fk_ms_reset64
#include <intrin.h>
#undef _interlockedbittestandset
#undef _interlockedbittestandreset
#undef _interlockedbittestandset64
#undef _interlockedbittestandreset64

/* SSE/SSE2/SSE3 intrinsic header. */
#include <emmintrin.h>

#ifdef __ICL
#	include <pmmintrin.h>
#endif

/* Statements only runs in debug time. */
#ifdef	_DEBUG
#	define	DEBUG_RUN( STMT )				STMT
#else
#	define	DEBUG_RUN( STMT )
#endif


/* Statements only runs while non-final version. */
#ifndef _FINAL
#	define	CHECK_RUN( STMT )				STMT
#else
#	define	CHECK_RUN( STMT )
#endif


/* Compiler specifications. */
#define	ALIGN1								__declspec(align(1))
#define	ALIGN4								__declspec(align(4))
#define	ALIGN8								__declspec(align(8))
#define	ALIGN16								__declspec(align(16))
#define	ALIGN32								__declspec(align(32))

#define	NOTHROW								__declspec(nothrow)
#define	NOINLINE							__declspec(noinline)
#define	DLLEXPORT							__declspec(dllexport)
#define	DLLIMPORT							__declspec(dllimport)

#define	DEPRECATED(Warning)					__declspec(deprecated("[xeres]:" #Warning))

/* Default to 16 byte data alignment. */
#define	ALIGNED								ALIGN16
#define	ALIGN_SIZE							(16)

/* Define CPU's cache line size(currently most CPU has 64 byte cache line). */
#define	CACHELINE_SIZE						(64)

/* Macro of calculating alignment of boundary. */
#define ALIGNOF( size , boundray )			(((size) + ((boundray)-1))&~((boundray)-1))

/* Determine if size is aligned. */
#define IS_ALIGNED( n , size )				((((size_t)(n))&(size-1))==0)


/* 64 bit pointer compliant( padding to calculate actual size ). */
#ifdef _WIN64
#	define	PAD64( NAME )
#else
#	define	PAD64( NAME )					__int32		__64bit_padding_##NAME
#endif

/* Constant string conversion. */
#define	_S( S )								L ## S

/* Indicate incompleted code. */
#define	incompleted							{ struct DEPRECATED( "code is incompleted" ) _i { bool code; } _incompleted = { false }; assert( _incompleted.code ); }

/* More types. */
#include "xtype.h"
